import {Suspense} from "react"
import { Route, Switch, NavLink, Link ,Redirect} from 'react-router-dom'
let RouterView = (PROPS)=>{
    console.log(PROPS);
    let {RouterList} = PROPS
    console.log(RouterList);
    let routerlist = RouterList.filter(item=>!item.to) // 正常渲染得路由
    let redirect = RouterList.filter(item=>item.to)[0]  // 重定向的路由
    console.log(routerlist,redirect);
    return (
        <Suspense fallback={<div>...加载中</div>}>
            <Switch>
                {
                     routerlist.map((item,index)=>{
                         return <Route path={item.path} key={index} render={(routerProps)=>{// 路由信息参数
                                return <item.component {...routerProps}></item.component>
                         }}></Route>
                     })
                }
                {
                    redirect?<Redirect from={redirect.from} to={redirect.to}></Redirect>:"暂无重定向"
                }
            </Switch>
        </Suspense>
    )
}
export default RouterView